package com.library.control.log;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.SimpleFormController;

import com.library.model.dto.notice.NoticeDTO;
import com.library.model.service.NoticeService;

public class NoticeBoardUpdateController extends SimpleFormController{
	
	private NoticeService noticeservice;

	public void setNoticeservice(NoticeService noticeservice) {
		this.noticeservice = noticeservice;
	}

	public NoticeBoardUpdateController() {
		
		this.setCommandClass(NoticeDTO.class);
		this.setCommandName("noticeUpdate");
		this.setFormView("noticeupdate");
	}
	
	public ModelAndView onSubmit(Object command) throws Exception {
		NoticeDTO noticedto=(NoticeDTO)command;
		noticeservice.updateNotice(noticedto);
		ModelAndView mav=new ModelAndView();
		mav.setViewName("redirect:/notice_boardlist.do");
		return mav;
	}
	
	public Map referenceData(HttpServletRequest request) throws Exception {
		int a_seq=Integer.parseInt(request.getParameter("a_seq"));
		NoticeDTO notice= noticeservice.getNotice(a_seq);
		Map<String, NoticeDTO> map
		   =new HashMap<String, NoticeDTO>();
		map.put("notice", notice);
		return map;
	}
	
	
	

}
